package cn.springcloudandalibaba.vo;

import cn.springcloudandalibaba.base.IBaseResult;

public class ResultVO<T> implements IBaseResult {
    private int code;
    private boolean success;
    private String message;
    private T data;

    private ResultVO(ResultCode resultCode,T data,String message) {
        this.code = resultCode.getCode();
        this.success = resultCode.getSuccess();
        this.message =message;
        this.data = data;
    }
    private ResultVO(ResultCode resultCode, T data) {
     this(resultCode,data,null);
    }
    public  static  <T> ResultVO<T> success(T data){
        return new ResultVO<>(ResultCode.SUCCESS, data);
    }
    public  static  <T> ResultVO<T> fail(String message){
        return new ResultVO<>(ResultCode.FAILED, null, message);
    }
    public  static  <T> ResultVO<T> fail(ResultCode resultCode){
        return new ResultVO<>(resultCode, null, resultCode.getMessage());
    }
    public  static  <T> ResultVO<T> fail(ResultCode resultCode,String message){
        return new ResultVO<>(resultCode, null, message);
    }

    public boolean getSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }
    public T getData() {
        return data;
    }

    public String getMessage() {
        return message;
    }
}
